package org.msfj.admin.setting.controller;

import org.msfj.admin.model.Log;
import org.msfj.admin.vo.LogVo;
import org.msfj.admin.model.Log;
import org.msfj.admin.vo.LogVo;
import org.msfj.admin.model.Log;
import org.msfj.admin.setting.service.LogService;
import org.msfj.admin.vo.LogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统日志controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:21
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统日志接口", tags = "系统日志接口")
@RestController
@RequestMapping("setting/log")
public class LogController extends BaseController{

    @Autowired
    private LogService logService;

    /**
     * 添加系统日志
     *
     * @param logVo
     * @return CommonResult.ok(LogVo)
     */
    @RequestMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统日志",notes = "添加系统日志")
    @ApiImplicitParam(value = "logVo",name = "logVo",dataType = "org.msfj.admin.setting.vo.LogVo",paramType = "query")
    public CommonResult addLog(LogVo logVo){
        Log log = logService.saveOrEdit(logVo);
        return CommonResult.ok(logService.setOtherProperties(log));
    }

    /**
     * 修改系统日志
     *
     * @param logVo
     * @return CommonResult.ok(LogVo)
     */
    @RequestMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统日志",notes = "修改系统日志")
    @ApiImplicitParam(value = "logVo",name = "logVo",dataType = "org.msfj.admin.setting.vo.LogVo",paramType = "query")
    public CommonResult editLog(LogVo logVo){
        Log log = logService.saveOrEdit(logVo);
        return CommonResult.ok(logService.setOtherProperties(log));
    }

    /**
     * 逻辑删除系统日志
     *
     * @param logVo
     * @return CommonResult.ok(LogVo)
     */
    @RequestMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统日志",notes = "逻辑删除系统日志")
    @ApiImplicitParam(value = "logVo",name = "logVo",dataType = "org.msfj.admin.setting.vo.LogVo",paramType = "query")
    public CommonResult delLog(LogVo logVo){
        Log log = logService.delById(logVo);
        return CommonResult.ok(logService.setOtherProperties(log));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @RequestMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统日志",notes = "逻辑删除系统日志")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam(value = "ids[]",required = false) List<String> ids) {
        Log log = new Log();
        logService.delByIds(ids, log);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统日志
     *
     * @param logVo
     * @return CommonResult.ok()
     */
    @RequestMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统日志",notes = "真实删除系统日志")
    @ApiImplicitParam(value = "logVo",name = "logVo",dataType = "org.msfj.admin.setting.vo.LogVo",paramType = "query")
    public CommonResult deleteLog(LogVo logVo){
        logService.trueDelById(logVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统日志
     *
     * @param logVo
     * @return CommonResult.ok(LogVo)
     */
    @RequestMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统日志",notes = "根据id查找系统日志")
    @ApiImplicitParam(value = "logVo",name = "logVo",dataType = "org.msfj.admin.setting.vo.LogVo",paramType = "query")
    public CommonResult getLog(LogVo logVo){
        Log log = logService.getById(logVo.getId());
        return CommonResult.ok(logService.setOtherProperties(log));
    }

    /**
     * 根据翻页参数、搜索参数查找系统日志
     *
     * @param notes
     * @param userIds
     * @param page     当前第几页
     * @param rows     每页多少条记录
     * @return CommonResult.ok(PageInfo<LogVo>)
     */
    @RequestMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统日志", notes = "根据翻页参数、搜索参数查找系统日志")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "notes", name = "notes", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "userIds", name = "userIds", dataType = "java.util.List", paramType = "query"),
            @ApiImplicitParam(value = "selectDateTime", name = "selectDateTime", dataType = "java.util.List", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "page", dataType = "Integer", paramType = "path"),
            @ApiImplicitParam(name = "rows", value = "rows", dataType = "Integer", paramType = "path")
    })
    public CommonResult findLogList(String notes, @RequestParam(value="userIds[]", required=false) List<Long> userIds, @RequestParam(value="selectDateTime[]", required=false) List<String> selectDateTime, Integer page, Integer rows) {
        PageInfo<LogVo> logVoPageInfo = logService.getByLog(notes,userIds,selectDateTime,page, rows);
        return CommonResult.ok(logVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统日志
     *
     * @param logVo
     * @return CommonResult.ok(List<LogVo>)
     */
    @RequestMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统日志",notes = "根据搜索参数查找所有系统日志")
    @ApiImplicitParam(value = "logVo",name = "logVo",dataType = "org.msfj.admin.setting.vo.LogVo",paramType = "query")
    public CommonResult getAllLog(LogVo logVo){
        List<LogVo> logVoList = logService.getAllLog(logVo);
        return CommonResult.ok(logVoList);
    }
}
